package 链表;

/**
 * @ClassName: _206_反转链表
 * @Description: _206_反转链表
 * @Date: 2021/5/31 12:00
 * @Create by: shuiren
 */
public class _206_反转链表 {

    public static ListNode reverseList(ListNode head) {

        if(head == null || head.next == null){
            return head;
        }

        //5,4,3,2,1
        ListNode result = null;
        ListNode temp;
        while (head != null){
            temp = head.next;
            head.next = result;
            result = head;
            head = temp;
        }

        return result;
    }

    public static void main(String[] args) {
        ListNode listNode5 = new ListNode(5,null);
        ListNode listNode4 = new ListNode(4,listNode5);
        ListNode listNode3 = new ListNode(3,listNode4);
        ListNode listNode2 = new ListNode(2,listNode3);
        ListNode listNode1 = new ListNode(1,listNode2);

        //链表顺序1,2,3,4,5
        reverseList(listNode1);
    }

}
